﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLogic.DTO.Test;
using BusinessLogic.Repository_Logic.Interfaces;
using PerpetuumSoft.Knockout;

namespace TestSystem.Controllers.Administrator
{
    public class QuestionController : Controller 
    {
        private IQuestionRepositoryLogic _questionRepositoryLogic;

        public QuestionController(IQuestionRepositoryLogic questionRepositoryLogic)
        {
            _questionRepositoryLogic = questionRepositoryLogic;
        }

        public ActionResult Index()
        {
            return View(_questionRepositoryLogic.GetAllQuestions());
        }

        public ActionResult addQuestion()
        {
            return View(_questionRepositoryLogic.GetEmptyQuestionDTO());
        }

        public string Save(QuestionDTO questionDto)
        {
            _questionRepositoryLogic.SaveQuestion(questionDto);
            return Url.Action("Index");
        }

        [HttpPost]
        public ActionResult Remove(int id)
        {
            _questionRepositoryLogic.RemoveQuestion(id);

            var results = new
            {
                Message = "Pomyślnie usunięto pytanie.",
                DeleteId = id,
                ItemCount = _questionRepositoryLogic.QuestionAmount()
            };
            return Json(results);
        }
    }
}
